import 'package:flutter/material.dart';
import 'package:toastification/toastification.dart';

class ToastService {
  static void showSuccess(String message, {String? title}) {
    toastification.show(
      type: ToastificationType.success,
      style: ToastificationStyle.fillColored,
      title: Text(title ?? '成功'),
      description: Text(message),
      alignment: Alignment.topCenter,
      autoCloseDuration: const Duration(seconds: 3),
      borderRadius: BorderRadius.circular(12.0),
      boxShadow: lowModeShadow,
      dragToClose: true,
      pauseOnHover: true,
    );
  }

  static void showError(String message, {String? title}) {
    toastification.show(
      type: ToastificationType.error,
      style: ToastificationStyle.fillColored,
      title: Text(title ?? '错误'),
      description: Text(message),
      alignment: Alignment.topCenter,
      autoCloseDuration: const Duration(seconds: 5),
      borderRadius: BorderRadius.circular(12.0),
      boxShadow: lowModeShadow,
      dragToClose: true,
      pauseOnHover: true,
    );
  }

  static void showWarning(String message, {String? title}) {
    toastification.show(
      type: ToastificationType.warning,
      style: ToastificationStyle.fillColored,
      title: Text(title ?? '警告'),
      description: Text(message),
      alignment: Alignment.topCenter,
      autoCloseDuration: const Duration(seconds: 4),
      borderRadius: BorderRadius.circular(12.0),
      boxShadow: lowModeShadow,
      dragToClose: true,
      pauseOnHover: true,
    );
  }

  static void showInfo(String message, {String? title}) {
    toastification.show(
      type: ToastificationType.info,
      style: ToastificationStyle.fillColored,
      title: Text(title ?? '信息'),
      description: Text(message),
      alignment: Alignment.topCenter,
      autoCloseDuration: const Duration(seconds: 3),
      borderRadius: BorderRadius.circular(12.0),
      boxShadow: lowModeShadow,
      dragToClose: true,
      pauseOnHover: true,
    );
  }

  static void showApiResponse({
    required bool success,
    required String message,
    String? successTitle,
    String? errorTitle,
  }) {
    if (success) {
      showSuccess(message, title: successTitle);
    } else {
      showError(message, title: errorTitle);
    }
  }

  static void showLoading(String message) {
    toastification.show(
      type: ToastificationType.info,
      style: ToastificationStyle.fillColored,
      title: const Text('请稍候'),
      description: Text(message),
      alignment: Alignment.topCenter,
      autoCloseDuration: const Duration(seconds: 2),
      borderRadius: BorderRadius.circular(12.0),
      showProgressBar: false,
      dragToClose: false,
    );
  }
}
